package apis

import (
	"github.com/gin-gonic/gin"
	"github.com/jinzhu/gorm"
	"goWebTest/goGinWebTest/common/logger"
	mysqldb "goWebTest/goGinWebTest/db"
	"goWebTest/goGinWebTest/service"
)

type Api struct {
	Context *gin.Context
	Logger  *logger.Helper
	Orm     *gorm.DB
	Errors  error
}

// MakeContext 设置http上下文
func (e *Api) GetContext() (*gin.Context, error) {
	return e.Context, nil
}

// MakeContext 设置http上下文
func (e *Api) MakeContext(c *gin.Context) *Api {
	e.Context = c
	return e
}

// GetOrm 获取Orm DB
func (e Api) GetOrm() (*gorm.DB, error) {
	return mysqldb.Db, nil
}

// MakeOrm 设置Orm DB
func (e *Api) MakeOrm() *Api {

	return e
}

func (e *Api) MakeService(c *service.Service) *Api {
	c.Log = e.Logger
	c.GormDb = e.Orm
	return e
}
